package com.win.cn.service;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import com.win.cn.core.model.NameControl;
import com.win.cn.core.model.SoftwareModel;

import javafx.collections.ObservableList;

/**
 * 软件服务
 * 
 * @author wangzh
 * 2018年6月11日 下午12:21:39
 */
public class SoftWareService {
	
	/**
	 * 读取软件
	 * @param softdata
	 */
	public void addData(ObservableList<SoftwareModel> softdata){
		try {
			BufferedReader buf=new BufferedReader(new InputStreamReader(new FileInputStream(NameControl.softFile)));
			String context="";
			String[] detail;
			while((context=buf.readLine())!=null){
				detail=context.split("\\,");
				softdata.add(new SoftwareModel(detail[0],detail[1],detail[2]));
			}
			buf.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	/**
	 * 启动软件
	 */
	public void startSoftWare(){
		try {
			 
			BufferedReader buf=new BufferedReader(new InputStreamReader(new FileInputStream(NameControl.softFile)));
			String context="";
			String[] detail;
			Integer time;
			while((context=buf.readLine())!=null){
				detail=context.split("\\,");
				 Runtime.getRuntime().exec(detail[1]).waitFor();
				 time=Integer.parseInt(detail[2]);
				 Thread.sleep(time*1000);
			}
			buf.close();
			
			
		} catch (IOException | InterruptedException e) {
			e.printStackTrace();
		}
	}

}
